package com.snj.main;



import java.lang.reflect.TypeVariable;
import java.util.Random;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;

import com.snj.lib.Global;
import com.snj.wef.R;
import com.snj.wef.WebActivity;
import com.snj.wef.ar.ARActivity;
import com.snj.wef.event.EventActivity;
import com.snj.wef.ranking.Tab_Ranking;
import com.snj.wef.selfwedding.SelfWeddingActivity;

public class MainActivity extends TabActivity {
	
	public static Context maincontext = null;
	
	private TabHost mTabHost;
	
	String tag = "MainActivity";
	
	ImageView[] img_topani = new ImageView[5];
	boolean[] checked = new boolean[39];

	private void setupTabHost() {
		mTabHost = (TabHost) findViewById(android.R.id.tabhost);
		//LocalActivityManager oo = this.ge
		
		mTabHost.setup(this.getLocalActivityManager());
	}
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// construct the tabhost
		setContentView(R.layout.activity_main);
		
		maincontext = this;
		
		img_topani[0] = (ImageView)findViewById(R.id.img_topani0);
		img_topani[1] = (ImageView)findViewById(R.id.img_topani1);
		img_topani[2] = (ImageView)findViewById(R.id.img_topani2);
		img_topani[3] = (ImageView)findViewById(R.id.img_topani3);
		img_topani[4] = (ImageView)findViewById(R.id.img_topani4);
		
		Random r = new Random();
		
		int ran = 0;
		int[] rans = new int[]{0, 4, 2, 5, 1, 7, 3, 6};
		
		AnimationDrawable ad = new AnimationDrawable();
		ad.setOneShot(false);
		
		
		for(int i=0; i<8; i++)
		{
			checked[i] = false;
		}
		
		ad = new AnimationDrawable();
		ad.setOneShot(false);
		
		for(int i=0; i<8; i++)
		{
			ran = rans[i];
			
			switch(ran)
			{
			case 0:				
				ad.addFrame(getResources().getDrawable(R.drawable.mask40), 250);
				break;
			case 1:				
				ad.addFrame(getResources().getDrawable(R.drawable.mask41), 250);
				break;
			case 2:				
				ad.addFrame(getResources().getDrawable(R.drawable.mask42), 250);
				break;
			case 3:				
				ad.addFrame(getResources().getDrawable(R.drawable.mask43), 250);
				break;
			case 4:				
				ad.addFrame(getResources().getDrawable(R.drawable.mask70), 250);
				break;
			case 5:				
				ad.addFrame(getResources().getDrawable(R.drawable.mask71), 250);
				break;
			case 6:				
				ad.addFrame(getResources().getDrawable(R.drawable.mask72), 250);
				break;
			case 7:				
				ad.addFrame(getResources().getDrawable(R.drawable.mask73), 250);
				break;
			}
		}
		
		img_topani[0].setImageDrawable(ad);
		ad.start();
		

		setupTabHost();
		//mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);

		TabSpec _CalendarTabSpec = mTabHost.newTabSpec("Calendar");
		
		setupTab(new Intent(MainActivity.this, WebActivity.class), R.drawable.menu_news);
		setupTab(new Intent(MainActivity.this, Tab_Ranking.class), R.drawable.menu_ranking);
		setupTab(new Intent(MainActivity.this, SelfWeddingActivity.class), R.drawable.menu_selfwedding);
		setupTab(new Intent(MainActivity.this, EventActivity.class), R.drawable.menu_event);
		setupTab(new Intent(MainActivity.this, ARActivity.class), R.drawable.menu_ar);
		
		mTabHost.addTab(mTabHost.newTabSpec("tab4")
		        .setIndicator(new LinearLayout(this))
		        .setContent(new Intent(this, EmptyActivity.class)));
		
		mTabHost.getTabWidget().getChildAt(5).setVisibility(View.GONE);
		//mTabHost.addTab(new Tabsp)
		
		mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
			
			@Override
			public void onTabChanged(String tabId) {
				// TODO Auto-generated method stub
				Log.d(tag, tabId);
				
				Global.isshown = false;
			}
		});
	}

	private void setupTab(final Intent intent, final int resId) {
		View tabview = null;
		
		switch(resId)
		{
		case R.drawable.menu_news:
			tabview = LayoutInflater.from(mTabHost.getContext()).inflate(R.layout.tabs_news, null);
			break;
			
		case R.drawable.menu_ranking:
			tabview = LayoutInflater.from(mTabHost.getContext()).inflate(R.layout.tabs_ranking, null);
			break;
			
		case R.drawable.menu_selfwedding:
			tabview = LayoutInflater.from(mTabHost.getContext()).inflate(R.layout.tabs_selfwedding, null);
			break;
			
		case R.drawable.menu_event:
			tabview = LayoutInflater.from(mTabHost.getContext()).inflate(R.layout.tabs_event, null);
			break;
			
		case R.drawable.menu_ar:
			tabview = LayoutInflater.from(mTabHost.getContext()).inflate(R.layout.tabs_ar, null);
			break;
		}
		
		

		TabSpec setContent = mTabHost.newTabSpec(String.format("%d", resId)).setIndicator(tabview).setContent(intent);
		mTabHost.addTab(setContent);
		//mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
	}

	private static View createTabView(final Context context, final int resId) {
		View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
		ImageView iv = (ImageView) view.findViewById(R.id.tabsimg);
		iv.setImageResource(resId);
		//iv.setBackgroundResource(resId);
		return view;
	}
	
	private static View createNewsView(final Context context, final int resId) {
		View view = LayoutInflater.from(context).inflate(R.layout.tabs_news, null);
		
		//iv.setBackgroundResource(resId);
		return view;
	}
}
